Changed behaviour of elapsed on response#687
Changed behaviour of elapsed on response#687gdhameeja wants to merge 2 commits intoencode:masterfrom
Conversation
florimondmanca
left a comment
There was a problem hiding this comment.
Thanks!
I like the approach taken here — feels more streamlined and natural than the previous strategy.
Just left a minor comment.
florimondmanca
left a comment
There was a problem hiding this comment.
Thanks! Marking this as mergeable for v0.10, since this does represent a change to current behavior.
Just realised there's a description of this property in the Response Developer Interface docs. Should we update it here as well?
I can update it. Should I? |
Would probably be best to have it with this PR, yes. :-) |
florimondmanca
left a comment
There was a problem hiding this comment.
Super, thank you! 🌟
lovelydinosaur
left a comment
There was a problem hiding this comment.
Fantastic stuff! Couple of very minor comments, tho I may look into addressing them myself so we can get this in shortly.
| self.is_closed = True | ||
| if hasattr(self, "_raw_stream"): | ||
| await self._raw_stream.aclose() | ||
| self._elapsed = self.request.timer.elapsed |
There was a problem hiding this comment.
Let's drop this inside the if not self.is_closed block.
| self.elapsed = datetime.timedelta(0) if elapsed is None else elapsed | ||
| self.call_next: typing.Optional[typing.Callable] = None | ||
|
|
||
| self.history = [] if history is None else list(history) |
There was a problem hiding this comment.
We probably also want to add self._elapsed = datetime.timedelta(0) inside the if stream is None block.
|
Great work on this! Pulled this into #692, with a few additional tweaks. |
Fixes #655
Makes elapsed time only available after response is closed
Took the django-rest-framework approach here (as making .data available only when
is_validis called)Used
ElapsedTimeron the request to start the timer and assigned theelapsedfrom request timer to response.